<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/icon/favicon.ico">
    <link rel="Shortcut Icon" href="/icon/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!--/meta 作为公共模版分离出去-->

    <title>添加用户 - H-ui.admin v3.1</title>
</head>
<body>
<article class="page-container">
    <form class="form form-horizontal" id="form-order-edit">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>收货人：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="receiverName" name="receiverName">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>联系电话：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" autocomplete="off" placeholder="" id="receiverPhone"
                       name="receiverPhone">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>地址类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="skin-minimal">
                    <div class="radio-box">
                        <input value="1" type="radio" id="radio-1" name="addressType">
                        <label for="radio-1">医院地址</label>
                    </div>
                    <div class="radio-box">
                        <input value="2" type="radio" id="radio-2" name="addressType">
                        <label for="radio-2">其他地址</label>
                    </div>
                </div>
            </div>
        </div>
        <div class="row cl" id="hospital">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>医院名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" onclick="chooseHospital()" readonly  class="input-text" autocomplete="off" value="" placeholder="" id="hospitalAddress" name="hospitalAddress">
            </div>
        </div>
        <div class="row cl" id="prov" style="display: none;">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>省市区：</label>
            <div class="formControls col-xs-8 col-sm-9" data-toggle="distpicker" id="distpicker">
                <select name="receiverState"></select>
                <select name="receiverCity"></select>
                <select name="receiverDistrict"></select>
                <input type="text" style="margin-top: 10px" id="otherAddress" class="input-text" autocomplete="off" value="" placeholder="村/街道/小区">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>详细地址：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" hidden autocomplete="off" value="" placeholder="" id="receiverAddress"
                       name="receiverAddress">
                <input type="text" class="input-text" autocomplete="off" value="" placeholder="" id="address"
                       name="address">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>预约时间：</label>
            <div class="formControls col-xs-6 col-sm-5">
                <input type="text" onfocus="WdatePicker({ minDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                       name="reserveTime" id="reserveTime" class="input-text Wdate" style="width:180px;" readonly="true">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>支付方式：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" name="paymentType" id="paymentType">
                    <option value="待定">待定</option>
                    <option value="现金">现金</option>
                    <option value="刷卡">刷卡</option>
                    <option value="微信">微信</option>
                    <option value="支付宝">支付宝</option>
                    </select>
                </span>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>医保类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" name="insuranceType" id="insuranceType">
                        <option value="" selected="selected" disabled="disabled" style="display: none"></option>
                        <option value="城职">城职</option>
                        <option value="城居/农合">城居/农合</option>
                        <option value="其他">其他</option>
                    </select>
                </span>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>医保地址：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" name="insurance" id="insurance">
                    <option value="" selected="selected" disabled="disabled" style="display: none"></option>
                    <option value="长沙">长沙</option>
                    <option value="株洲">株洲</option>
                    <option value="湘潭">湘潭</option>
                    <option value="益阳">益阳</option>
                    <option value="常德">常德</option>
                    <option value="岳阳">岳阳</option>
                    <option value="娄底">娄底</option>
                    <option value="邵阳">邵阳</option>
                    <option value="怀化">怀化</option>
                    <option value="湘西">湘西</option>
                    <option value="湘西">郴州</option>
                    <option value="湘西">张家界</option>
                    <option value="湘西">衡阳</option>
                    <option value="湘西">永州</option>
                    <option value="湘西">省外</option>
                    <option value="湘西">无医保</option>
                    </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">备注：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea  class="textarea" id="prescriptionPic" name="prescriptionPic" placeholder="" ></textarea>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>药品清单：</label>
            <div class="formControls col-xs-8 col-sm-9" id="list" >
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input id="saveButton" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="lib/province/distpicker.data.js"></script>
<script type="text/javascript" src="lib/province/distpicker.js"></script>
<script type="text/javascript" src="lib/common.js"></script>

<script type="text/javascript">

    var order = parent.order;
    var addressType = order.addressType || ""
    var medicineList= order.medicineList;
    if (order.orderId){
        $("#receiverName").val(order.receiverName);
        $("#receiverPhone").val(order.receiverPhone);
        $("#reserveTime").val(order.reserveTime);
        $("#paymentType").val(order.paymentType);
        $("#insuranceType").val(order.insuranceType);
        $("#insurance").val(order.insurance);
        $("#prescriptionPic").val(order.prescriptionPic);
        if (order.reserveTime) {
            var time = dateAll(order.reserveTime)
            $("#reserveTime").val(time);
        }

        if(order.addressType=='1'){
            $("#radio-1").attr('checked', 'checked');
            radioCheck();
            $("#hospital").show()
            $("#prov").hide()
            $("#hospitalAddress").val(order.receiverAddress.split("|")[0] || "")
        }else{
            $("#radio-2").attr('checked', 'checked');
            radioCheck();
            $("#prov").show()
            $("#hospital").hide()
            $("#otherAddress").val(order.receiverAddress.split("|")[0] || "")
        }
        $("#address").val(order.receiverAddress.split("|")[1] || "");
        for (var i=0;i<medicineList.length;i++){

            $('#list').append('<span>'+medicineList[i].medicineName + medicineList[i].standard +' 数量</span><input name="medicineList['+i+'].num" type="number" class="input-text" value="'+medicineList[i].num+'">')
            $('#list').append('<input type="text" hidden name="medicineList['+i+'].itemId" class="input-text" value="'+medicineList[i].itemId+'">')
        }

    }

    function radioCheck(){
        $('.skin-minimal input').iCheck({
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        })
        $("input:radio[name='addressType']").on('ifChecked', function (event) {
            var value = $(this).val()
            addressType =value
            if (value == "1") {
                $("#hospital").show()
                $("#prov").hide()
            } else if (value == "2") {
                $("#prov").show()
                $("#hospital").hide()
            }
        });
    }

    $('#distpicker').distpicker({
        province: order.receiverState || "湖南省",
        city: order.receiverCity,
        district:  order.receiverDistrict
    });


    /*文本输入限制*/
    $(".textarea").Huitextarealength({
        minlength: 0,
        maxlength: 100
    });


    $("#form-order-edit").validate({
        rules: {
            receiverName: {
                required: true,
                minlength: 2
            },
            receiverAddress: {
                required: true
            }
        },
        onkeyup: false,
        focusCleanup: false,
        success: "valid",
        submitHandler: function (form) {
            var index = layer.load(3);
            if (addressType == "1"){
                $("#receiverAddress").val( $("#hospitalAddress").val() +"|"+$("#address").val())
            } else {
                $("#receiverAddress").val( $("#otherAddress").val() +"|"+$("#address").val())
            }
            $(form).ajaxSubmit({
                url:"./order/"+order.orderId+"/update",
                method:"post",
                success: function (data) {
                    layer.close(index);
                    if (data.success == true) {
                        if (parent.location.pathname != '/') {
                            parent.refresh();
                            parent.msgSuccess("编辑成功!");
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        } else {
                            layer.confirm('编辑成功!', {
                                btn: ['确认'], icon: 1
                            }, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            });
                        }
                    } else {
                        layer.close(index);
                        layer.alert('编辑失败! ' + data.message, {title: '错误信息', icon: 2});
                    }
                },
                error: function (XMLHttpRequest) {
                    layer.close(index);
                    layer.alert('数据处理失败! 错误码:' + XMLHttpRequest.status + ' 错误信息:' + JSON.parse(XMLHttpRequest.responseText).message, {
                        title: '错误信息',
                        icon: 2
                    });
                }
            });
        }
    });

    function chooseHospital() {
        layer_show("选择医院", "choose-hospital");
    }

    function setHospital(hospital) {
        $('#distpicker').distpicker({
            province: hospital.hospitalProvince || "湖南省",
            city: hospital.hospitalCity,
            district:  hospital.hospitalDis
        });
        $('#hospitalAddress').val(hospital.hospitalName)

    }
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>